Repository navigation
Add widget id to blocks in the widgets screen - #28379
Conversation
|
Size Change: -81 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
| export function cloneBlock( block, mergeAttributes = {}, newInnerBlocks ) { | ||
| const clientId = uuid(); | ||
|
|
||
| const sanitizedAttributes = sanitizeBlockAttributes( block.name, { |
There was a problem hiding this comment.
The addition of sanitize could potentially have a small performance impact (not sure if noticeable), the other thing is that it was not an expectation of cloneBock and I hope it doesn't produce unexpected side effects
There was a problem hiding this comment.
Does running npm run test-performance with and without this PR demonstrate any performance regression?
| ...block, | ||
| attributes: { | ||
| ...( block.attributes || {} ), | ||
| __internalWidgetId: widgetId, |
There was a problem hiding this comment.
It's a bit weird that we add an attribute that is not registered. I'm fine with it but I hope it's something that can break if for some reason, in the future, we apply the same "sanitizeAttributes" behavior in flows where it's not applied right now.
Let's make sure we've tests to cover this.
There was a problem hiding this comment.
I'm fine with it but I hope it's something that can break if for some reason, in the future, we apply the same "sanitizeAttributes" behavior in flows where it's not applied right now.
I'm not sure what you meant by that? What kind of tests you have in mind?
There was a problem hiding this comment.
Not particular tests in my mind, this is meant to fix widgets updating if I'm not wrong, let's just make sure it's covered because it can easily break.
e1ea247 to
46003d8
Compare
|
|
||
| return state || {}; | ||
| } | ||
|
|
| ...block.attributes, | ||
| ...mergeAttributes, | ||
| }, | ||
| attributes: sanitizedAttributes, |
There was a problem hiding this comment.
Could you please add a new unit test for cloneBlock() which tests that attributes are sanitised? (And, maybe while you're at it, double check that createBlock() has one.)
|
Let's document this change of |
Description
Mentioned in this Slack thread. Basically, this PR tries to fix a saving issue in the widgets screen after merging #27885 (comment). The recap was well documented in a Slack thread comment.
The solution is to inject
__internalWidgetIdto all blocks in the widgets screen but not in their block types attributes, and modify thecloneBlockfunction to only clone attributes specified inside the block types (following the same logic increateBlock).This PR also partially reverts #28078, specifically the
__unstableCloneValuehack.How has this been tested?
Types of changes
Breaking change
Checklist: